<?php
/**
 * Created by PhpStorm.
 * User: hao
 * Date: 2018/10/22
 * Time: 2:19 PM
 */

namespace app\api\controller\v1;
use app\api\model\Banner as BannerModel;
use app\api\validate\IDMustBePostiveInt;
use app\lib\exception\BannerMissException;

class Banner
{
    /*
     * 获取指定id的banner信息
     * @http GET
     * @url /banner/:id
     * @id banner的id号
     */
    public function getBanner($id) {

//        $data = [
//          'id'=> $id,
//        ];
        //validate独立验证
//        $validate = new Validate([
//            'name' => 'require|max:10',
//            'email'=> 'email',
//        ]);

//        $result = $validate->check($data);

        (new IDMustBePostiveInt())->goCheck();
        $banner = BannerModel::getBannerByID($id);
        if (!$banner) {
            throw new BannerMissException();
        }
        return json($banner);
    }
}